package com.hsav.kcxb.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.hsav.kcxb.R;
import com.hsav.kcxb.view.MusicClipView3;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

public class MusicClipActivity extends BaseActivity implements View.OnClickListener {
    private MusicClipView3 musicClipView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_clip);
        initView();
    }

    private void initView() {
        ImageView imgBack = (ImageView) findViewById(R.id.img_back);
        imgBack.setOnClickListener(this);
        TextView textSingAll = (TextView) findViewById(R.id.text_sing_all);
        textSingAll.setOnClickListener(this);
        TextView textRecordClip = (TextView) findViewById(R.id.text_record_clip);
        textRecordClip.setOnClickListener(this);
        TextView textLoop = (TextView) findViewById(R.id.text_loop_exercise);
        textLoop.setOnClickListener(this);

        musicClipView = (MusicClipView3) findViewById(R.id.musicClipView);
        musicClipView.getRootContent().loadLrc(new File(getApplication().getCacheDir(), "cbg.lrc"));
    }

    @Override
    public void onClick(View v) {
        Calendar startTime = Calendar.getInstance();
        startTime.setTime(new Date(musicClipView.getRootContent().getStartTime()));
        Calendar endTime = Calendar.getInstance();
        endTime.setTime(new Date(musicClipView.getRootContent().getEndTime()));
        int startTimeMinutes = startTime.get(Calendar.MINUTE);
        int startTimeSeconds = startTime.get(Calendar.SECOND);
        int endTimeMinutes = endTime.get(Calendar.MINUTE);
        int endTimeSeconds = endTime.get(Calendar.SECOND);
        switch (v.getId())
        {
            case R.id.img_back:
                finish();
                Toast.makeText(this, "用户点击了返回按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.text_sing_all:
                Toast.makeText(this, "用户点击了唱整首按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.text_record_clip:
                Toast.makeText(this, String.format("用户点击了录制片段按钮，开始时间%02d:%02d，结束时间%02d:%02d", startTimeMinutes, startTimeSeconds, endTimeMinutes, endTimeSeconds), Toast.LENGTH_SHORT).show();
                break;
            case R.id.text_loop_exercise:
                Toast.makeText(this, String.format("用户点击了循环练习按钮，开始时间%02d:%02d，结束时间%02d:%02d", startTimeMinutes, startTimeSeconds, endTimeMinutes, endTimeSeconds), Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
